package com.app.controller;

import com.app.common.EducationTool;
import com.app.common.ExperienceTool;
import com.app.common.ScaleTool;
import com.app.mapper.akesai.ComRecruitersAkesaiMapper;
import com.app.mapper.akesai.EnterpriseAkesaiMapper;
import com.app.mapper.akesai.JobPublishAkesaiMapper;
import com.app.mapper.akesai.UserAkesaiMapper;
import com.app.mapper.dunhuang.ComRecruitersDunhuangMapper;
import com.app.mapper.dunhuang.EnterpriseDunhuangMapper;
import com.app.mapper.dunhuang.JobPublishDunhuangMapper;
import com.app.mapper.dunhuang.UserDunhuangMapper;
import com.app.mapper.guazhou.ComRecruitersGuazhouMapper;
import com.app.mapper.guazhou.EnterpriseGuazhouMapper;
import com.app.mapper.guazhou.JobPublishGuazhouMapper;
import com.app.mapper.guazhou.UserGuazhouMapper;
import com.app.mapper.jinta.ComRecruitersJintaMapper;
import com.app.mapper.jinta.EnterpriseJintaMapper;
import com.app.mapper.jinta.JobPublishJintaMapper;
import com.app.mapper.jinta.UserJintaMapper;
import com.app.mapper.subei.ComRecruitersSubeiMapper;
import com.app.mapper.subei.EnterpriseSubeiMapper;
import com.app.mapper.subei.JobPublishSubeiMapper;
import com.app.mapper.subei.UserSubeiMapper;
import com.app.mapper.suzhou.*;
import com.app.mapper.yumen.ComRecruitersYumenMapper;
import com.app.mapper.yumen.EnterpriseYumenMapper;
import com.app.mapper.yumen.JobPublishYumenMapper;
import com.app.mapper.yumen.UserYumenMapper;
import com.app.model.*;
import com.app.service.AdminUserService;
import com.app.util.Result;
import com.app.util.TokenUtils;
import com.app.vo.ComRecruitersVo;
import com.app.vo.JobPublishVo;
import com.app.vo.JobVo;
import com.google.common.collect.Maps;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@Controller
public class PublishController {
    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    private JobPublishSuzhouMapper jobPublishSuzhouMapper;
    @Autowired
    private JobPublishJintaMapper jobPublishJintaMapper;
    @Autowired
    private JobPublishDunhuangMapper jobPublishDunhuangMapper;
    @Autowired
    private JobPublishGuazhouMapper jobPublishGuazhouMapper;
    @Autowired
    private JobPublishYumenMapper jobPublishYumenMapper;
    @Autowired
    private JobPublishSubeiMapper jobPublishSubeiMapper;
    @Autowired
    private JobPublishAkesaiMapper jobPublishAkesaiMapper;

    @Autowired
    private EnterpriseSuzhouMapper enterpriseSuzhouMapper;
    @Autowired
    private EnterpriseJintaMapper enterpriseJintaMapper;
    @Autowired
    private EnterpriseDunhuangMapper enterpriseDunhuangMapper;
    @Autowired
    private EnterpriseGuazhouMapper enterpriseGuazhouMapper;
    @Autowired
    private EnterpriseYumenMapper enterpriseYumenMapper;
    @Autowired
    private EnterpriseSubeiMapper enterpriseSubeiMapper;
    @Autowired
    private EnterpriseAkesaiMapper enterpriseAkesaiMapper;

    @Autowired
    private ComRecruitersSuzhouMapper comRecruitersSuzhouMapper;
    @Autowired
    private ComRecruitersJintaMapper comRecruitersJintaMapper;
    @Autowired
    private ComRecruitersDunhuangMapper comRecruitersDunhuangMapper;
    @Autowired
    private ComRecruitersGuazhouMapper comRecruitersGuazhouMapper;
    @Autowired
    private ComRecruitersYumenMapper comRecruitersYumenMapper;
    @Autowired
    private ComRecruitersSubeiMapper comRecruitersSubeiMapper;
    @Autowired
    private ComRecruitersAkesaiMapper comRecruitersAkesaiMapper;

    @Autowired
    private UserSuzhouMapper userSuzhouMapper;
    @Autowired
    private UserJintaMapper userJintaMapper;
    @Autowired
    private UserDunhuangMapper userDunhuangMapper;
    @Autowired
    private UserGuazhouMapper userGuazhouMapper;
    @Autowired
    private UserYumenMapper userYumenMapper;
    @Autowired
    private UserSubeiMapper userSubeiMapper;
    @Autowired
    private UserAkesaiMapper userAkesaiMapper;


    @Autowired
    private IndustryMapper industryMapper;

    @Autowired
    private PositionMapper positionMapper;
    /**
     * 岗位列表
     *
     * @param page
     * @param limit
     * @param keyWord
     * @param state
     * @param startTime
     * @param endTime
     * @param orderDate
     * @param request
     * @return
     */
    @GetMapping("/getPublishListByModel")
    public Result<Object> getPublishListByModel(
            int page, int limit,
            @RequestParam(required = false) String keyWord,
            @RequestParam(required = false) Integer state,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) Integer orderDate,
            @RequestParam(required = false) Integer addressId,
            @RequestParam(required = false) Integer enrollId,
            HttpServletRequest request) {
        String token = request.getHeader("token");
        String userId = TokenUtils.nothingness(token);
        if (userId == null) {
            return Result.error(405, "token不存在");
        }
        AdminUserModel user = adminUserService.getUserById(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        JobPublishVo vo = new JobPublishVo();
        JobPublishModel model = new JobPublishModel();
        model.setPage((page - 1) * limit);
        if (enrollId != null) {
            model.setEnrollId(enrollId);
        }
        model.setLimit(limit);
        model.setKeyword(keyWord);
        model.setStartTime(startTime);
        model.setEndTime(endTime);
        model.setOrderDate(orderDate);
        model.setRecruitState(state);
        if (addressId != null && addressId != 0) {
            if (addressId == 1) {
                return Result.success(suzhouPublishList(model));
            } else if (addressId == 2) {
                return Result.success(jintaPublishList(model));
            } else if (addressId == 3) {
                return Result.success(dunhuangPublishList(model));
            } else if (addressId == 4) {
                return Result.success(guazhouPublishList(model));
            } else if (addressId == 5) {
                return Result.success(yumenPublishList(model));
            } else if (addressId == 6) {
                return Result.success(subeiPublishList(model));
            } else if (addressId == 7) {
                return Result.success(akesaiPublishList(model));
            }
        } else {
            int suzhouCount = jobPublishSuzhouMapper.getJobPublishCountByModel(model);
            int jintaCount = jobPublishJintaMapper.getJobPublishCountByModel(model);
            int dunhuangCount = jobPublishDunhuangMapper.getJobPublishCountByModel(model);
            int guazhouCount = jobPublishGuazhouMapper.getJobPublishCountByModel(model);
            int yumenCount = jobPublishYumenMapper.getJobPublishCountByModel(model);
            int subeiCount = jobPublishSubeiMapper.getJobPublishCountByModel(model);
            int akesaiCount = jobPublishAkesaiMapper.getJobPublishCountByModel(model);
            int pageCount = suzhouCount / limit;
            int remainderResult = suzhouCount % limit;
            if (pageCount + 1 >= page) {
                vo = suzhouPublishList(model);
            }
            if (page > pageCount) {
                if (page == pageCount + 1 && remainderResult > 0) {
                    model.setLimit(limit - remainderResult);
                    model.setPage(page - pageCount);
                    vo.getList().addAll(jintaPublishList(model).getList());
                }
                if (page > pageCount + 1) {
                    model.setLimit(limit);
                    model.setPage((page - (pageCount + 2)) * limit);
                    vo = jintaPublishList(model);
                }
                int pageCount2 = (suzhouCount + jintaCount) / limit;
                int remainderResult2 = (suzhouCount + jintaCount) % limit;
                if (page > pageCount2) {
                    if (page == pageCount2 + 1 && remainderResult2 > 0) {
                        model.setLimit(limit - remainderResult2);
                        model.setPage(page - pageCount2);
                        vo.getList().addAll(dunhuangPublishList(model).getList());
                    }
                    if (page > pageCount2 + 1) {
                        model.setLimit(limit);
                        model.setPage((page - (pageCount2 + 2)) * limit);
                        vo = dunhuangPublishList(model);
                    }
                    int pageCount3 = (suzhouCount + jintaCount + dunhuangCount) / limit;
                    int remainderResult3 = (suzhouCount + jintaCount + dunhuangCount) % limit;
                    if (page > pageCount3) {
                        if (page == pageCount3 + 1 && remainderResult3 > 0) {
                            model.setLimit(limit - remainderResult3);
                            model.setPage(page - pageCount3);
                            vo.getList().addAll(guazhouPublishList(model).getList());
                        }
                        if (page > pageCount3 + 1) {
                            model.setLimit(limit);
                            model.setPage((page - (pageCount3 + 2)) * limit);
                            vo = guazhouPublishList(model);
                        }
                        int pageCount4 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount) / limit;
                        int remainderResult4 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount) % limit;
                        if (page > pageCount4) {
                            if (page == pageCount4 + 1 && remainderResult4 > 0) {
                                model.setLimit(limit - remainderResult4);
                                model.setPage(page - pageCount4);
                                vo.getList().addAll(yumenPublishList(model).getList());
                            }
                            if (page > pageCount4 + 1) {
                                model.setLimit(limit);
                                model.setPage((page - (pageCount4 + 2)) * limit);
                                vo = yumenPublishList(model);
                            }
                            int pageCount5 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount + yumenCount) / limit;
                            int remainderResult5 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount + yumenCount) % limit;
                            if (page > pageCount5) {
                                if (page == pageCount5 + 1 && remainderResult5 > 0) {
                                    model.setLimit(limit - remainderResult5);
                                    model.setPage(page - pageCount5);
                                    vo.getList().addAll(subeiPublishList(model).getList());
                                }
                                if (page > pageCount5 + 1) {
                                    model.setLimit(limit);
                                    model.setPage((page - (pageCount5 + 2)) * limit);
                                    vo = subeiPublishList(model);
                                }
                                int pageCount6 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount + yumenCount + subeiCount) / limit;
                                int remainderResult6 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount + yumenCount + subeiCount) % limit;
                                if (page > pageCount6) {
                                    if (page == pageCount6 + 1 && remainderResult6 > 0) {
                                        model.setLimit(limit - remainderResult6);
                                        model.setPage(page - pageCount6);
                                        vo.getList().addAll(akesaiPublishList(model).getList());
                                    }
                                    if (page > pageCount6 + 1) {
                                        model.setLimit(limit);
                                        model.setPage((page - (pageCount6 + 2)) * limit);
                                        vo = akesaiPublishList(model);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            vo.setCount(jintaCount + suzhouCount + dunhuangCount + guazhouCount + yumenCount + subeiCount + akesaiCount);
        }
        return Result.success(vo);
    }


    @GetMapping("/findPublishListById")
    public Result<Object> findPublishListById(
            Integer id,
            Integer addressId,
            HttpServletRequest request) {
        String token = request.getHeader("token");
        String userId = TokenUtils.nothingness(token);
        if (userId == null) {
            return Result.error(405, "token不存在");
        }
        AdminUserModel user = adminUserService.getUserById(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        if (addressId != null && addressId != 0) {
            if (addressId == 1) {
                return Result.success(suzhouPublishListById(id));
            } else if (addressId == 2) {
                return Result.success(jintaPublishListById(id));
            } else if (addressId == 3) {
                return Result.success(dunhuangPublishListById(id));
            } else if (addressId == 4) {
                return Result.success(guazhouPublishListById(id));
            } else if (addressId == 5) {
                return Result.success(yumenPublishListById(id));
            } else if (addressId == 6) {
                return Result.success(subeiPublishListById(id));
            } else if (addressId == 7) {
                return Result.success(akesaiPublishListById(id));
            }
        }
        return null;
    }


    //1肃州
    private JobPublishVo suzhouPublishList(JobPublishModel model) {
        List<JobPublishModel> modelList = jobPublishSuzhouMapper.getJobPublishListByModel(model);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        for (int i = 0; i < modelList.size(); i++) {
            String bir = sdf.format(modelList.get(i).getCrtTime());
            modelList.get(i).setCrtTimeText(bir);
            modelList.get(i).setEnterprise(enterpriseSuzhouMapper.selectById(modelList.get(i).getEnrollId()));
            if (modelList.get(i).getRecruitState() == 1) {
                modelList.get(i).setRecruitStateText("待审核");
            } else if (modelList.get(i).getRecruitState() == 2) {
                modelList.get(i).setRecruitStateText("未过审");
            } else if (modelList.get(i).getRecruitState() == 3) {
                modelList.get(i).setRecruitStateText("开放中");
            } else if (modelList.get(i).getRecruitState() == 4) {
                modelList.get(i).setRecruitStateText("已关闭");
            }
            modelList.get(i).setAddressId(1);
            modelList.get(i).setAddressText("肃州区");
        }
        int count = jobPublishSuzhouMapper.getJobPublishCountByModel(model);
        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return vo;
    }


    public JobPublishModel suzhouPublishListById(int id) {
        JobPublishModel job = jobPublishSuzhouMapper.getModelById(id);
        JobVo jobvo = new JobVo();
        jobvo.setCode(1);
        ComRecruitersModel com = comRecruitersSuzhouMapper.getComRecruitersById(job.getRecId());
        job.setComRecruiters(com);
        EnterpriseModel enterprise = enterpriseSuzhouMapper.selectById(job.getEnrollId());
        job.setEnterprise(enterprise);
        String scaleName = "";
        String enterpriseName = "";
        for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
            int scale = ScaleTool.SCALE_VO_LIST.get(j).getId();
            int scaleId = enterprise.getScaleId();
            if (scale == scaleId) {
                scaleName = ScaleTool.SCALE_VO_LIST.get(j).getData();
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(enterprise.getEnterpriseType());
        enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
        enterprise.setScaleName(scaleName);
        if (com != null) {
            com.setEnterprise(enterprise);
            com.setUser(userSuzhouMapper.getModelByRid(com.getId()));
            job.setComRecruiters(com);
        }
        int expId = job.getExpId();
        int eduId = job.getEduId();
        int jobType = job.getJobType();
        for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
            if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                job.setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
            }
        }
        for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
            if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                job.setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
            }
        }

        job.setJobTypeText(positionMapper.getModelById(jobType).getJobTitle());

        return job;
    }

    //2金塔
    private JobPublishVo jintaPublishList(JobPublishModel model) {
        List<JobPublishModel> modelList = jobPublishJintaMapper.getJobPublishListByModel(model);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        for (int i = 0; i < modelList.size(); i++) {
            String bir = sdf.format(modelList.get(i).getCrtTime());
            modelList.get(i).setCrtTimeText(bir);
            modelList.get(i).setEnterprise(enterpriseJintaMapper.selectById(modelList.get(i).getEnrollId()));
            if (modelList.get(i).getRecruitState() == 1) {
                modelList.get(i).setRecruitStateText("待审核");
            } else if (modelList.get(i).getRecruitState() == 2) {
                modelList.get(i).setRecruitStateText("未过审");
            } else if (modelList.get(i).getRecruitState() == 3) {
                modelList.get(i).setRecruitStateText("开放中");
            } else if (modelList.get(i).getRecruitState() == 4) {
                modelList.get(i).setRecruitStateText("已关闭");
            }
            modelList.get(i).setAddressId(2);
            modelList.get(i).setAddressText("金塔县");
        }
        int count = jobPublishJintaMapper.getJobPublishCountByModel(model);
        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return vo;
    }


    public JobPublishModel jintaPublishListById(int id) {
        JobPublishModel job = jobPublishJintaMapper.getModelById(id);
        JobVo jobvo = new JobVo();
        jobvo.setCode(1);
        ComRecruitersModel com = comRecruitersJintaMapper.getComRecruitersById(job.getRecId());
        job.setComRecruiters(com);
        EnterpriseModel enterprise = enterpriseJintaMapper.selectById(job.getEnrollId());
        job.setEnterprise(enterprise);
        String scaleName = "";
        String enterpriseName = "";
        for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
            int scale = ScaleTool.SCALE_VO_LIST.get(j).getId();
            int scaleId = enterprise.getScaleId();
            if (scale == scaleId) {
                scaleName = ScaleTool.SCALE_VO_LIST.get(j).getData();
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(enterprise.getEnterpriseType());
        enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
        enterprise.setScaleName(scaleName);
        if (com != null) {
            com.setEnterprise(enterprise);
            com.setUser(userJintaMapper.getModelByRid(com.getId()));
            job.setComRecruiters(com);
        }
        int expId = job.getExpId();
        int eduId = job.getEduId();
        int jobType = job.getJobType();
        for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
            if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                job.setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
            }
        }
        for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
            if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                job.setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
            }
        }

        job.setJobTypeText(positionMapper.getModelById(jobType).getJobTitle());

        return job;
    }

    //3敦煌
    private JobPublishVo dunhuangPublishList(JobPublishModel model) {
        List<JobPublishModel> modelList = jobPublishDunhuangMapper.getJobPublishListByModel(model);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        for (int i = 0; i < modelList.size(); i++) {
            String bir = sdf.format(modelList.get(i).getCrtTime());
            modelList.get(i).setCrtTimeText(bir);
            modelList.get(i).setEnterprise(enterpriseDunhuangMapper.selectById(modelList.get(i).getEnrollId()));
            if (modelList.get(i).getRecruitState() == 1) {
                modelList.get(i).setRecruitStateText("待审核");
            } else if (modelList.get(i).getRecruitState() == 2) {
                modelList.get(i).setRecruitStateText("未过审");
            } else if (modelList.get(i).getRecruitState() == 3) {
                modelList.get(i).setRecruitStateText("开放中");
            } else if (modelList.get(i).getRecruitState() == 4) {
                modelList.get(i).setRecruitStateText("已关闭");
            }
            modelList.get(i).setAddressId(3);
            modelList.get(i).setAddressText("敦煌市");
        }
        int count = jobPublishDunhuangMapper.getJobPublishCountByModel(model);
        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return vo;
    }


    public JobPublishModel dunhuangPublishListById(int id) {
        JobPublishModel job = jobPublishDunhuangMapper.getModelById(id);
        JobVo jobvo = new JobVo();
        jobvo.setCode(1);
        ComRecruitersModel com = comRecruitersDunhuangMapper.getComRecruitersById(job.getRecId());
        job.setComRecruiters(com);
        EnterpriseModel enterprise = enterpriseDunhuangMapper.selectById(job.getEnrollId());
        job.setEnterprise(enterprise);
        String scaleName = "";
        String enterpriseName = "";
        for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
            int scale = ScaleTool.SCALE_VO_LIST.get(j).getId();
            int scaleId = enterprise.getScaleId();
            if (scale == scaleId) {
                scaleName = ScaleTool.SCALE_VO_LIST.get(j).getData();
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(enterprise.getEnterpriseType());
        enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
        enterprise.setScaleName(scaleName);
        if (com != null) {
            com.setEnterprise(enterprise);
            com.setUser(userDunhuangMapper.getModelByRid(com.getId()));
            job.setComRecruiters(com);
        }
        int expId = job.getExpId();
        int eduId = job.getEduId();
        int jobType = job.getJobType();
        for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
            if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                job.setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
            }
        }
        for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
            if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                job.setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
            }
        }

        job.setJobTypeText(positionMapper.getModelById(jobType).getJobTitle());

        return job;
    }

    //4瓜州
    private JobPublishVo guazhouPublishList(JobPublishModel model) {
        List<JobPublishModel> modelList = jobPublishGuazhouMapper.getJobPublishListByModel(model);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        for (int i = 0; i < modelList.size(); i++) {
            String bir = sdf.format(modelList.get(i).getCrtTime());
            modelList.get(i).setCrtTimeText(bir);
            modelList.get(i).setEnterprise(enterpriseGuazhouMapper.selectById(modelList.get(i).getEnrollId()));
            if (modelList.get(i).getRecruitState() == 1) {
                modelList.get(i).setRecruitStateText("待审核");
            } else if (modelList.get(i).getRecruitState() == 2) {
                modelList.get(i).setRecruitStateText("未过审");
            } else if (modelList.get(i).getRecruitState() == 3) {
                modelList.get(i).setRecruitStateText("开放中");
            } else if (modelList.get(i).getRecruitState() == 4) {
                modelList.get(i).setRecruitStateText("已关闭");
            }
            modelList.get(i).setAddressId(4);
            modelList.get(i).setAddressText("瓜州县");
        }
        int count = jobPublishGuazhouMapper.getJobPublishCountByModel(model);
        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return vo;
    }

    public JobPublishModel guazhouPublishListById(int id) {
        JobPublishModel job = jobPublishGuazhouMapper.getModelById(id);
        JobVo jobvo = new JobVo();
        jobvo.setCode(1);
        ComRecruitersModel com = comRecruitersGuazhouMapper.getComRecruitersById(job.getRecId());
        job.setComRecruiters(com);
        EnterpriseModel enterprise = enterpriseGuazhouMapper.selectById(job.getEnrollId());
        job.setEnterprise(enterprise);
        String scaleName = "";
        String enterpriseName = "";
        for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
            int scale = ScaleTool.SCALE_VO_LIST.get(j).getId();
            int scaleId = enterprise.getScaleId();
            if (scale == scaleId) {
                scaleName = ScaleTool.SCALE_VO_LIST.get(j).getData();
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(enterprise.getEnterpriseType());
        enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
        enterprise.setScaleName(scaleName);
        if (com != null) {
            com.setEnterprise(enterprise);
            com.setUser(userGuazhouMapper.getModelByRid(com.getId()));
            job.setComRecruiters(com);
        }
        int expId = job.getExpId();
        int eduId = job.getEduId();
        int jobType = job.getJobType();
        for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
            if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                job.setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
            }
        }
        for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
            if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                job.setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
            }
        }

        job.setJobTypeText(positionMapper.getModelById(jobType).getJobTitle());

        return job;
    }


    //5玉门
    private JobPublishVo yumenPublishList(JobPublishModel model) {
        List<JobPublishModel> modelList = jobPublishYumenMapper.getJobPublishListByModel(model);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        for (int i = 0; i < modelList.size(); i++) {
            String bir = sdf.format(modelList.get(i).getCrtTime());
            modelList.get(i).setCrtTimeText(bir);
            modelList.get(i).setEnterprise(enterpriseYumenMapper.selectById(modelList.get(i).getEnrollId()));
            if (modelList.get(i).getRecruitState() == 1) {
                modelList.get(i).setRecruitStateText("待审核");
            } else if (modelList.get(i).getRecruitState() == 2) {
                modelList.get(i).setRecruitStateText("未过审");
            } else if (modelList.get(i).getRecruitState() == 3) {
                modelList.get(i).setRecruitStateText("开放中");
            } else if (modelList.get(i).getRecruitState() == 4) {
                modelList.get(i).setRecruitStateText("已关闭");
            }
            modelList.get(i).setAddressId(5);
            modelList.get(i).setAddressText("玉门市");
        }
        int count = jobPublishYumenMapper.getJobPublishCountByModel(model);
        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return vo;
    }

    public JobPublishModel yumenPublishListById(int id) {
        JobPublishModel job = jobPublishYumenMapper.getModelById(id);
        JobVo jobvo = new JobVo();
        jobvo.setCode(1);
        ComRecruitersModel com = comRecruitersYumenMapper.getComRecruitersById(job.getRecId());
        job.setComRecruiters(com);
        EnterpriseModel enterprise = enterpriseYumenMapper.selectById(job.getEnrollId());
        job.setEnterprise(enterprise);
        String scaleName = "";
        String enterpriseName = "";
        for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
            int scale = ScaleTool.SCALE_VO_LIST.get(j).getId();
            int scaleId = enterprise.getScaleId();
            if (scale == scaleId) {
                scaleName = ScaleTool.SCALE_VO_LIST.get(j).getData();
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(enterprise.getEnterpriseType());
        enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
        enterprise.setScaleName(scaleName);
        if (com != null) {
            com.setEnterprise(enterprise);
            com.setUser(userYumenMapper.getModelByRid(com.getId()));
            job.setComRecruiters(com);
        }
        int expId = job.getExpId();
        int eduId = job.getEduId();
        int jobType = job.getJobType();
        for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
            if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                job.setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
            }
        }
        for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
            if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                job.setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
            }
        }

        job.setJobTypeText(positionMapper.getModelById(jobType).getJobTitle());

        return job;
    }


    //6肃北
    private JobPublishVo subeiPublishList(JobPublishModel model) {
        List<JobPublishModel> modelList = jobPublishSubeiMapper.getJobPublishListByModel(model);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        for (int i = 0; i < modelList.size(); i++) {
            String bir = sdf.format(modelList.get(i).getCrtTime());
            modelList.get(i).setCrtTimeText(bir);
            modelList.get(i).setEnterprise(enterpriseSubeiMapper.selectById(modelList.get(i).getEnrollId()));
            if (modelList.get(i).getRecruitState() == 1) {
                modelList.get(i).setRecruitStateText("待审核");
            } else if (modelList.get(i).getRecruitState() == 2) {
                modelList.get(i).setRecruitStateText("未过审");
            } else if (modelList.get(i).getRecruitState() == 3) {
                modelList.get(i).setRecruitStateText("开放中");
            } else if (modelList.get(i).getRecruitState() == 4) {
                modelList.get(i).setRecruitStateText("已关闭");
            }
            modelList.get(i).setAddressId(6);
            modelList.get(i).setAddressText("肃北县");
        }
        int count = jobPublishSubeiMapper.getJobPublishCountByModel(model);
        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return vo;
    }

    public JobPublishModel subeiPublishListById(int id) {
        JobPublishModel job = jobPublishSubeiMapper.getModelById(id);
        JobVo jobvo = new JobVo();
        jobvo.setCode(1);
        ComRecruitersModel com = comRecruitersSubeiMapper.getComRecruitersById(job.getRecId());
        job.setComRecruiters(com);
        EnterpriseModel enterprise = enterpriseSubeiMapper.selectById(job.getEnrollId());
        job.setEnterprise(enterprise);
        String scaleName = "";
        String enterpriseName = "";
        for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
            int scale = ScaleTool.SCALE_VO_LIST.get(j).getId();
            int scaleId = enterprise.getScaleId();
            if (scale == scaleId) {
                scaleName = ScaleTool.SCALE_VO_LIST.get(j).getData();
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(enterprise.getEnterpriseType());
        enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
        enterprise.setScaleName(scaleName);
        if (com != null) {
            com.setEnterprise(enterprise);
            com.setUser(userSubeiMapper.getModelByRid(com.getId()));
            job.setComRecruiters(com);
        }
        int expId = job.getExpId();
        int eduId = job.getEduId();
        int jobType = job.getJobType();
        for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
            if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                job.setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
            }
        }
        for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
            if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                job.setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
            }
        }

        job.setJobTypeText(positionMapper.getModelById(jobType).getJobTitle());

        return job;
    }


    //7阿克塞
    private JobPublishVo akesaiPublishList(JobPublishModel model) {
        List<JobPublishModel> modelList = jobPublishAkesaiMapper.getJobPublishListByModel(model);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        for (int i = 0; i < modelList.size(); i++) {
            String bir = sdf.format(modelList.get(i).getCrtTime());
            modelList.get(i).setCrtTimeText(bir);
            modelList.get(i).setEnterprise(enterpriseAkesaiMapper.selectById(modelList.get(i).getEnrollId()));
            if (modelList.get(i).getRecruitState() == 1) {
                modelList.get(i).setRecruitStateText("待审核");
            } else if (modelList.get(i).getRecruitState() == 2) {
                modelList.get(i).setRecruitStateText("未过审");
            } else if (modelList.get(i).getRecruitState() == 3) {
                modelList.get(i).setRecruitStateText("开放中");
            } else if (modelList.get(i).getRecruitState() == 4) {
                modelList.get(i).setRecruitStateText("已关闭");
            }
            modelList.get(i).setAddressId(7);
            modelList.get(i).setAddressText("阿克塞县");
        }
        int count = jobPublishAkesaiMapper.getJobPublishCountByModel(model);
        JobPublishVo vo = new JobPublishVo();
        vo.setList(modelList);
        vo.setCount(count);
        return vo;
    }

    public JobPublishModel akesaiPublishListById(int id) {
        JobPublishModel job = jobPublishAkesaiMapper.getModelById(id);
        JobVo jobvo = new JobVo();
        jobvo.setCode(1);
        ComRecruitersModel com = comRecruitersAkesaiMapper.getComRecruitersById(job.getRecId());
        job.setComRecruiters(com);
        EnterpriseModel enterprise = enterpriseAkesaiMapper.selectById(job.getEnrollId());
        job.setEnterprise(enterprise);
        String scaleName = "";
        String enterpriseName = "";
        for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
            int scale = ScaleTool.SCALE_VO_LIST.get(j).getId();
            int scaleId = enterprise.getScaleId();
            if (scale == scaleId) {
                scaleName = ScaleTool.SCALE_VO_LIST.get(j).getData();
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(enterprise.getEnterpriseType());
        enterprise.setEnterpriseTypeText(industryModel.getIndustryName());
        enterprise.setScaleName(scaleName);
        if (com != null) {
            com.setEnterprise(enterprise);
            com.setUser(userAkesaiMapper.getModelByRid(com.getId()));
            job.setComRecruiters(com);
        }
        int expId = job.getExpId();
        int eduId = job.getEduId();
        int jobType = job.getJobType();
        for (int j = 0; j < ExperienceTool.EXPERIENCE_VO_LIST.size(); j++) {
            if (expId == ExperienceTool.EXPERIENCE_VO_LIST.get(j).getId()) {
                job.setExpRequireText(ExperienceTool.EXPERIENCE_VO_LIST.get(j).getData());
            }
        }
        for (int j = 0; j < EducationTool.EDUCATION_VO_LIST.size(); j++) {
            if (eduId == EducationTool.EDUCATION_VO_LIST.get(j).getId()) {
                job.setMinEducationText(EducationTool.EDUCATION_VO_LIST.get(j).getData());
            }
        }

        job.setJobTypeText(positionMapper.getModelById(jobType).getJobTitle());

        return job;
    }

    /**
     * 岗位导出
     * @param response
     * @param jobPublishModel
     */
    @PostMapping({"/exportPublish"})
    @ResponseBody
    public void exportPublish(HttpServletResponse response, @RequestBody  JobPublishModel jobPublishModel) {
        Map<String, Object> map = Maps.newHashMap();
        jobPublishModel.setPage(0);
        jobPublishModel.setLimit(99999);
        if (jobPublishModel.getAddressId() != null && jobPublishModel.getAddressId() != 0) {
            if (jobPublishModel.getAddressId() == 1) {
                JobPublishVo list = suzhouPublishList(jobPublishModel);
                map.put("list", list.getList());
            } else if (jobPublishModel.getAddressId() == 2) {
                JobPublishVo list = jintaPublishList(jobPublishModel);
                map.put("list", list.getList());
            } else if (jobPublishModel.getAddressId() == 3) {
                JobPublishVo list = dunhuangPublishList(jobPublishModel);
                map.put("list", list.getList());
            } else if (jobPublishModel.getAddressId() == 4) {
                JobPublishVo list = guazhouPublishList(jobPublishModel);
                map.put("list", list.getList());
            } else if (jobPublishModel.getAddressId() == 5) {
                JobPublishVo list = yumenPublishList(jobPublishModel);
                map.put("list", list.getList());
            } else if (jobPublishModel.getAddressId() == 6) {
                JobPublishVo list = subeiPublishList(jobPublishModel);
                map.put("list", list.getList());
            } else if (jobPublishModel.getAddressId() == 7) {
                JobPublishVo list = akesaiPublishList(jobPublishModel);
                map.put("list", list.getList());
            }
        } else {
            List<JobPublishModel> list = new ArrayList<>();
            JobPublishVo list1 = suzhouPublishList(jobPublishModel);
            JobPublishVo list2 = jintaPublishList(jobPublishModel);
            JobPublishVo list3 = dunhuangPublishList(jobPublishModel);
            JobPublishVo list4 = guazhouPublishList(jobPublishModel);
            JobPublishVo list5 = yumenPublishList(jobPublishModel);
            JobPublishVo list6 = subeiPublishList(jobPublishModel);
            JobPublishVo list7 = akesaiPublishList(jobPublishModel);
            list.addAll(list1.getList());
            list.addAll(list2.getList());
            list.addAll(list3.getList());
            list.addAll(list4.getList());
            list.addAll(list5.getList());
            list.addAll(list6.getList());
            list.addAll(list7.getList());
            map.put("list", list);
        }
        ClassPathResource classPathResource = new ClassPathResource("C:/jyx/酒泉市管理后台/职位花名册.xlsx");
        String path = classPathResource.getPath();
        TemplateExportParams templateExportParams1 = new TemplateExportParams(path);
        Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map);
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss"));
        String fileName = "招聘人员花名册" + time + ".xlsx";
        try {
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            response.flushBuffer();
            wb.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
